Repository navigation
feat: Add CLI-driven event sync with Watch and Refresh - #2679
Draft
murarustefaan wants to merge 13 commits into
Draft
murarustefaan wants to merge 13 commits into
murarustefaan wants to merge 13 commits into
Conversation
Adds the SDK-side vocabulary for event-based syncing: Op, Change, WatchOptions, Position, Ready, RefreshResource, the optional WatchClient interface and SyncOptions.Refresh. Plugin.WatchReady, Plugin.Watch and Plugin.Ack type-assert the client to WatchClient and return ErrNotImplemented otherwise. None of them takes Plugin.mu: a watch stream is long-lived and must not block the refresh syncs that run alongside it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
NewKeysRecord builds the one-row record that identifies a single resource by its primary keys, always in table.PrimaryKeys() order so the same resource always produces the same record. KeysString renders one as "col=val,col=val" for logging and for coalescing changes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Builds the delete message for a single resource from its keys record: one AND group of EQ predicates, one per primary key column, plus the relations of every descendant table so destinations can cascade the delete. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Refresh re-fetches individual resources by their keys and runs the items the Refresher returns through the regular resolve pipeline: column resolvers, PostResourceResolver, relations, CQID calculation and insert batching. It emits no migrate messages and never multiplexes, since the caller already knows the table and the client. OP_DELETE skips the fetch and ErrNotFound turns into a delete message. A resource that fails is reported as a SyncError and does not stop the others; all failures come back joined. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Watch drives the stream handshake - Start, Ready, Position, Change..., Drained - forwards the client's Acks while changes stream out, and reports Unimplemented for plugins that do not implement WatchClient. Sync maps Sync.Request.refresh into SyncOptions.Refresh. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A watch stream can sit idle between changes, so the server pings idle connections every 30s and permits client pings without a stream. Shutdown now lets in-flight RPCs finish, falling back to a hard stop after 30s so a long-lived watch cannot hold the server open. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Exercises the handshake and drain, ack forwarding, the first message having to be Start, Unimplemented without a WatchClient, and refresh syncs producing inserts for found keys and delete records for missing ones. The refresh-while-watching case fails if Plugin.Watch takes the plugin lock. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The example now implements plugin.WatchClient and scheduler.Refresher so an event-based sync can be driven end to end without a cloud behind it. Two optional spec fields: `changes` replays canned events over the Watch stream, `refresh_data` holds the rows a refresh sync can find. WatchReady connects to the state backend and reports the checkpoint stored under `events:checkpoint`; Ack writes it back and flushes. Full syncs are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
WatchReady is called first and alone; Watch and Ack then run concurrently from different goroutines for the lifetime of the stream, and an Ack routinely lands while Watch is blocked. Neither the SDK nor the gRPC server locks around them, and a refresh Sync can run on the same client at the same time, so implementations must guard whatever the two share. Close can also land on a live watch. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Watch read the checkpoint while Ack wrote it, and Close nil'd the state client that Ack dereferences, all without synchronization. A mutex now covers stateClient and checkpoint; Ack holds it for the whole write, so Close waits for an in-flight ack instead of closing underneath it. Adds two tests that drive Watch, Ack and Close concurrently. Both report a data race against the previous code under -race. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ared AWS tables keep _cq_id as their only primary key and carry resource identity in PrimaryKeyComponent columns, which is also what Resource.CalculateCQID hashes. Keying on PrimaryKeys() rejected every one of them. Table.IdentityColumns() now defines the set once - components when the table declares any, otherwise primary keys - and NewKeysRecord, NewDeleteRecordByKeys and the refresh delete path all use it. KeysString is unchanged, since it just walks the record it is given. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…records An event rarely knows a resource's whole identity: aws_iam_policies has identity columns account_id, id, input_hash and arn, while a CloudTrail event carries only account_id and arn. Requiring all of them rejected those tables outright. A keys record may now carry any non-empty subset of the identity columns, still in the table's declaration order, and deletes predicate on exactly the columns present. Columns outside the identity set, and empty records, are still rejected. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Source plugins can implement
WatchClientandRefresher, and the SDK serves theWatchRPC and refresh syncs, where a failed refresh of one resource is reported as a sync error and does not fail the call.Depends on cloudquery/plugin-pb-go#729.
go.modrequires the releasedplugin-pb-go, so the build fails until that pull request is released.Use the following steps to ensure your PR is ready to be reviewed
go fmtto format your code 🖊golangci-lint run🚨 (install golangci-lint here)